#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define str string
#define all(x) (x).begin(),(x).end()
#define ms(a,t) memset(a,t,sizeof(a))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define db double
const int maxn = 4000+10;
const int mod = 999999999;
const ll INF = 0x3f3f3f3f;
const db eps = 1e-7;
int n,m;
ll a[maxn][maxn];
ll b[maxn][maxn],c[maxn][maxn];
ll tmp[maxn];
void Solve() {
	cin >> n >> m;
	for(int t = 1,id,dir,op,x,w,y; t <= m; t++) {
		cin >> id;
		if(id == 1) {
			cin >> dir >> x >> op >> w;
			if(dir == 0) {
				for(y = 1; y <= n; y++) tmp[y] = -a[x][y];
				if(op == 1) for(y = 1; y <= n; y++) a[x][y] &= w;
				else if(op == 2) for(y = 1; y <= n; y++) a[x][y] |= w;
				else if(op == 3) for(y = 1; y <= n; y++) a[x][y] ^= w;
				else for(y = 1; y <= n; y++) a[x][y] += w,((a[x][y]>=mod)?(a[x][y] -= ((a[x][y]-mod>=mod)?(2*mod):mod)):0); 
				for(y = 1; y <= n; y++) tmp[y] += a[x][y]+tmp[y-1];
				for(y = 1; y <= n; y++) b[x][y] += tmp[y];
			} else {
				for(y = 1; y <= n; y++) tmp[y] = -a[y][x];
				if(op == 1) for(y = 1; y <= n; y++) a[y][x] &= w;
				else if(op == 2) for(y = 1; y <= n; y++) a[y][x] |= w;
				else if(op == 3) for(y = 1; y <= n; y++) a[y][x] ^= w;
				else for(y = 1; y <= n; y++) a[y][x] += w,((a[y][x]>=mod)?(a[y][x] -= ((a[y][x]-mod>=mod)?(2*mod):mod)):0); 
				for(y = 1; y <= n; y++) tmp[y] += a[y][x]+tmp[y-1];
				for(y = 1; y <= n; y++) c[y][x] += tmp[y];
			}
		} else {
			cin >> x >> y;
			ll sum = 0;
			for(int i = 1; i <= x; i++) {
				sum += b[i][y];
			}
			for(int i = 1; i <= y; i++) {
				sum += c[x][i];
			}
			cout<<sum<<'\n';
		}
//		for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) { cerr<<a[i][j]<<' '; } cerr<<'\n'; } cerr<<'\n';
//		for(int i = 1; i <= n; i++) { for(int j = 1; j <= n; j++) { cerr<<b[i][j]<<' '; } cerr<<'\n'; } cerr<<'\n';
	}
}
int main() {
	freopen("fire.in","r",stdin);
	freopen("fire.out","w",stdout);
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//	cerr<<sizeof(b)*3/1024.0/1024<<'\n';
//	int T; cin >> T; while(T--)
	Solve();
	return 0;
}
